home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1997 / MacHack 1997.toast / Hacks / Hacks ’96 / Talking Telnet / source / Speech / AnnoyingSpeechMode.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-06-22  |  1.2 KB  |  62 lines  |  [TEXT/CWIE]

  1. #include    "speech.proto.h"
  2. #include    "rsdefs.h"
  3.  
  4.  
  5. void SpeakStream(unsigned char *ptr, short len)
  6. {
  7.     OSErr    err;
  8.     
  9.     do {
  10.         if (!gCanSpeak) {
  11.             break;
  12.         }
  13.         
  14.         /* Stop the old speech channel */
  15.         
  16.         StopSpeaking();
  17.         
  18.         /* Get a speech channel */
  19.         
  20.         gSpeakingVoiceIndex = gSelectedVoiceIndex;
  21.         MoveHHi((Handle)gVoices);
  22.         HLock((Handle)gVoices);
  23.         err = NewSpeechChannel(&(*gVoices)[gSpeakingVoiceIndex], &gSpeechChannel);
  24.         HUnlock((Handle)gVoices);
  25.         if (noErr != err) {
  26.         
  27.             /* The voice that the user selected doesn't work; let's try the rest */
  28.             
  29.             HLock((Handle)gVoices);
  30.             for (gSpeakingVoiceIndex = 0; gSpeakingVoiceIndex < gNumberVoices; gSpeakingVoiceIndex++) {
  31.                 err = NewSpeechChannel(&(*gVoices)[gSpeakingVoiceIndex], &gSpeechChannel);
  32.                 if (noErr == err) {
  33.                     break;
  34.                 }
  35.             }
  36.             HUnlock((Handle)gVoices);
  37.             if (gSpeakingVoiceIndex == gNumberVoices) {
  38.                 StopSpeaking();
  39.                 break;
  40.             }
  41.         }
  42.         
  43.         /* Start speaking the new text */
  44.         
  45.         err = SpeakText(gSpeechChannel, (char *)ptr, len);
  46.         if (noErr != err) {
  47.             StopSpeaking();
  48.             break;
  49.         }
  50.         
  51.         /* Flash the selection, and fix the menu */
  52.         
  53.         while (SpeechBusy()) {
  54.         }
  55.         
  56.         
  57.     } while (false);
  58.     
  59.     if (noErr != err) {
  60.         DoSpeechError(err);
  61.     }
  62. }